#-*- coding: utf-8 -*-


import sys
import os

os.urandom(24)


reload(sys)
sys.setdefaultencoding('utf8')

from flask import Flask,render_template,session,request,jsonify
app = Flask(__name__)

from modules import message

@app.route('/')
@app.route('/index')
def index():
    return render_template('index.html')

@app.route('/login',methods=['GET','POST'])
def login():
    if request.method == 'GET':
        return render_template('login.html')

@app.route('/logout')
def logout():
    del session['phone']
    pass

@app.route('/message/send',methods=['GET','POST'])
def send():
    result = {}
    if request.method == 'POST':
        args = request.form.to_dict()
        if 'content' in args and 'phone' in args:
            m = message.Message(**args)
            result = m.send()
        else:
            result = {'code':100,
                      'message':'please post phone and content'}
            return jsonify(result)
    return render_template('message.html',result=result)

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=9000,debug=True)